package com.hawk_an;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;


public class Visual extends JFrame{
	private static final long serialVersionUID = 1L;
	private int init = 0;
	protected BufferedImage bufferImage;
	protected Graphics2D bgr;
	private int width, height;
	private GameGraphics grafik = new GameGraphics();
	private Judge game;

	public Visual(int inwidth,int inheight,Judge ingame){
		game = ingame;
		width = inwidth;
		height = inheight;
		setLayout(new FlowLayout());
//		addKeyListener(new KeyListner());
		setResizable(false);
		setTitle("Fyra i rad");
		setIgnoreRepaint( true );
		setBackground(Color.black);
        pack();
		setDefaultCloseOperation(EXIT_ON_CLOSE);
//        BufferedImage image = null;
//        try {
//            image = ImageIO.read(getClass().getResource("/asteroidsicon.png"));
//        }
//        catch (IOException e) {
//            e.printStackTrace();
//        }
//        setIconImage(image);
		setVisible(true);
		setSize(new Dimension(width,height));
	}
	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D)g;
		if(init < 1){
			bufferImage = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
		    bgr = (Graphics2D) bufferImage.getGraphics();
		    bgr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			init ++;
		}
		bgr.setColor(Color.black);
		bgr.fillRect(0, 0, width, height);
		bgr.setColor(Color.blue);
		bgr.fillRect(width/20, height/13, width - 2*(width)/20, height- (height/13));
		bgr.setColor(Color.white);
		grafik.paint(bgr,width,height);
		
	    if (bufferImage != null)
	        g2.drawImage(bufferImage, 0, 0, null);
		repaint();
	}
}









